{% extends 'base.html' %}
{% block content %}

<div class="container">
    <div style="margin-bottom: 10px" class="clearfix">
        <div class="mt-3 btn btn-primary" >
                筛选条件：
        </div>
        <div style="width: 500px">
            <form method="get">
                <div class="col-lg-6">
<!--                    <div class="input-group">-->
<!--                        <input type="text" name="q" class="form-control" placeholder="请输入IP..." value={{ search_data }}>-->
<!--                        <span class="input-group-btn">-->
<!--                            <button class="btn btn-default" type="submit">-->
<!--                                <span class="glyphicon glyphicon-search" aria-hidden="true"></span>-->
<!--                            </button>-->
<!--                        </span>-->
<!--                    </div>&lt;!&ndash; /input-group &ndash;&gt;-->
                    <div class="input-group">
                         <span>IP地址</span> ：<input type="text" name="q1" class="form-control" placeholder="请输入IP..." value={{ search_data1 }}>
                    </div>

                    <div class="input-group">
                         <span>地区</span> ：<input type="text" name="q2" class="form-control" placeholder="请输入地区..." value={{ search_data2 }}>
                    </div>

                    <div class="input-group">
                         <span>厂商</span> ：<input type="text" name="q3" class="form-control" placeholder="请输入厂商..." value={{ search_data3 }}>
                    </div>


                    <span class="input-group-btn">
                        <button class="btn btn-default" type="submit">
                            搜索
                            <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                        </button>
                    </span>
                </div><!-- /.col-lg-6 -->
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            <!--span class="glyphicon glyphicon-th-list" aria-hidden="true"></span-->
            <span>选择要配置的设备:</span>
        </div>
        <form method="POST">
            {% csrf_token %}
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th><input type="checkbox" name="device" value="{{ device.id }}" id="button_all"></th>
                        <th>管理IP</th>
                        <th>设备名称</th>
                        <th>地区</th>
                        <th>型号</th>
                    </tr>
                </thead>
                <tbody>
                {% for device in devices %}
                <tr>
                    <td><input type="checkbox" name="device" value="{{ device.id }}"></td>
                    <td>{{device.ip_address}}</td>
                    <td>{{device.dev_name}}</td>
                    <td>{{device.diqu}}</td>
                    <td>{{device.xinghao}}</td>
                </tr>
                {% endfor %}
                </tbody>
            </table>

            <h4 class="mt-3">华为设备命令</h4>
            <textarea class="form-control" rows="5" name="huawei_command"></textarea>
            <h4 class="mt-3">思科设备命令</h4>
            <textarea class="form-control" rows="5" name="cisco_command"></textarea>
            <br>
            <button type="submit" class="mt-3 btn btn-primary">提交命令</button>
        </form>
    </div>
    <div class="clearfix">
        <ul class="pagination" style="float:left;">
            {{ page_string }}
            <li>
                <form method="get" style="float: left;margin-left: -1px">
                    <div class="input-group" style="width: 110px">
                        <input type="text" name="page" class="form-control" placeholder="页码">
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-default">跳转</button>
                        </span>
                    </div>
                </form>
            </li>

        </ul>
    </div>
</div>
<script>
    //1.获取元素
    var button_all = document.getElementById('button_all')
    var button_son = document.querySelector('tbody').getElementsByTagName('input')
<!--    console.log(button_all)-->
<!--    console.log(button_son)-->

    //2.注册事件
    button_all.onclick = function(){
        for (var i=0;i<button_son.length;i++){
            button_son[i].checked = this.checked
        }
    }

    //给每个小按钮绑定一个点击事件
    for (var i=0;i<button_son.length;i++){
        button_son[i].onclick = function(){
            var flag = true
            for (var j = 0;j<button_son.length;j++){
                if(!button_son[j].checked){
                    flag = false
                }
                button_all.checked = flag
            }
        }
    }
</script>
{% endblock content %}